#include "ballmdl.h"

SBallModel::SBallModel(int initSize, QRect bounds) :
    SBehavior(bounds.center(), QSize(initSize, initSize), bounds)
{
    r = 100;
    wz = hz = r;
    doBounce = true;
    velocityCapture = true;
}
//---------------------------------------------------------------------------

void SBallModel::Integrate(float dt)
{
    wz = hz = r;

    x += vx*dt;
    y += vy*dt;

    vw = Gr*(wz - w);
    vh = Gr*(hz - h);
    w += vw*dt;
    h += vh*dt;

    SBehavior::Integrate(dt);
}
//---------------------------------------------------------------------------

void SBallModel::bounceEvent(bool collide, SBounceEdges &edges)
{
    if (doBounce)
    {
        if (FZone == bzOut || FZone == bzAway)
            FZone = bzEdge;

        if (edges.left)
        {
            x = Xmin + w;
            vx = -vx*k;
        }
        if (edges.top)
        {
            y = Ymin + h;
            vy = -vy*k;
        }
        if (edges.right)
        {
            x = Xmax - w;
            vx = -vx*k;
        }
        if (edges.bottom)
        {
            y = Ymax - h;
            vy = -vy*k;
        }
    }
}
//---------------------------------------------------------------------------
